package com.thti.mecool.client.command.result.work;


import com.thti.mecool.client.base.BaseActivity;
import com.thti.mecool.client.base.Cache;
import com.thti.mecool.client.base.HandlerConstant;
import com.thti.mecool.client.command.ICommand;
import com.thti.mecool.client.model.biz.WorkmemoBizImpl;
import com.thti.mecool.client.protocol.work.GetWorkmemoResult;
import com.thti.mecool.client.service.Protocol;

public class GetWorkmemoCommand implements ICommand{

	@Override
	public void doCommand(Object o) {
		GetWorkmemoResult getWorkmemoResult=(GetWorkmemoResult)o;
		if(getWorkmemoResult!=null){
			if(getWorkmemoResult.getStatus()==1){
				WorkmemoBizImpl workmemoBizImpl=new WorkmemoBizImpl(Cache.getmContext());
				if(getWorkmemoResult.getPage().getPage()==0)
				workmemoBizImpl.deleteTable("workmemo");
//				for(MemoDto m:getWorkmemoResult.getMemos()){
//					workmemoBizImpl.save(m,getWorkmemoResult.getPage().getPage()+1);
//				}
				workmemoBizImpl.saveAll(getWorkmemoResult.getMemos(), getWorkmemoResult.getPage().getPage()+1);
				if(getWorkmemoResult.getPage().isHasNext())
					BaseActivity.setDataFlag(HandlerConstant.WorkMemosHasNextCommand);
				else
				BaseActivity.setDataFlag(HandlerConstant.WorkMemosCommand);
			}else{
				BaseActivity.setFailName("工作备忘");
				BaseActivity.setCurrentMesg(getWorkmemoResult.getMsg());
				BaseActivity.setDataFlag(HandlerConstant.CommandFail);
			}
		}
	}
	@Override
	public String getCommandID() {
		return Protocol.getWorkmemo;
	}
	@Override
	public Class<?> getCommandClass() {
		// TODO Auto-generated method stub
		return GetWorkmemoResult.class;
	}
}
